<?php

namespace App\Admin\Controllers;

use App\Models\Robot;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;

class RobotController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(Robot::with(['user', 'pair.site']), function (Grid $grid) {
            $grid->fixColumns(2, -2);
            $grid->model()->where('type', '!=', 0)->orderBy('updated_at', 'desc');
            $grid->column('id')->sortable();
            $grid->column('user_id');
            $grid->column('user.email', '用户邮箱');
            $grid->column('user.mobile', '用户手机号');
            $grid->column('pair_id');
            $grid->column('pair.site.site_name', '交易所');
            $grid->column('pair.symbol', '交易对');
            $grid->column('policy_type')->using(['1'=> '单次', '2'=> '多次']);
            $grid->column('type')->using(["1"=>"系统推荐型", "2"=>"高频型", "3"=>"激进型", "4"=>"稳健性", "5"=>"保守型", "6"=>"自定义", "7"=>"系统推荐型2", "8"=>"新手策略"]);
            $grid->column('first_number');
            $grid->column('size');
            $grid->column('limit_win_rate');
            $grid->column('limit_lose_rate');
            $grid->column('back_win_rate');
            $grid->column('back_lose_rate');
            $grid->column('limit_lose_rates');
            $grid->column('first_double')->bool();
            $grid->column('cover_type')->using(['avg'=>'均价补仓', 'last'=>'按最后一手补仓价格补仓']);
            $grid->column('open_enable')->bool();
            $grid->column('close_enable')->bool();
            $grid->column('open_period');
            $grid->column('close_period');
            $grid->column('close_win_rate');
            $grid->column('can_buy')->bool();
            $grid->column('win_stop')->bool();
            $grid->column('status')->using(['opening'=>'等待开仓', 'working' => '工作中', 'stopped'=>'已停止', 'frozen'=> '已冻结']);
            $grid->column('created_at');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
                $filter->equal('user_id');
                $filter->equal('user.email', '用户邮箱');
                $filter->equal('user.mobile', '用户手机号');
                $filter->equal('pair_id');
                $filter->equal('pair.site.site_name', '交易所');
                $filter->equal('pair.symbol', '交易对');
                $filter->equal('status')->select(['opening'=>'等待开仓', 'working' => '工作中', 'stopped'=>'已停止', 'frozen'=> '已冻结']);
            });
            $grid->disableBatchDelete();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->disableCreateButton();
        });
    }
}
